import React from 'react';
import { connect } from 'react-redux';
import { AppState } from '@redux/reducers';
import { bindActionCreators } from 'redux';
import { requestLogOut } from '@redux/actions/user';
import { IGlobalReduceState } from '@/redux/reducers/global';
import { withRouter, RouteComponentProps } from 'react-router-dom';

type IProps = IGlobalReduceState & RouteComponentProps & {
    requestLogOut:typeof requestLogOut
};
class NavbarRight extends React.Component<IProps> {

    constructor(props:IProps){
        super(props);
    }
    
    render(){
        let title;
        if (this.props.userInfo){
            title= (<div className="NavbarRight-Wrapper " onClick={()=>this.props.history.push({pathname:'personalCenter'})}>
            {this.props.userInfo.nickname}
            </div>)
        }
        
        else { 
            title= (<div className="NavbarRight-Wrapper Login-Register-CSS" onClick={()=>this.props.history.push({pathname:'login'})}>
            登录/注册
            </div>)
        }
        return(
            title
        )
    }
}
export default connect(
    (state:AppState)=> state.global,
    (dispatch)=>
        bindActionCreators({
            requestLogOut
        },
        dispatch
    )

)(withRouter(NavbarRight));